const app = getApp()
Page({
  data: {
    domainName: app.domainName,
    inputPhone:'',
    iswhow:'hide',
    isTop:0,
    isTop2:264,
    fadeOut:'',
    z10:'z10',
    isfrom:1
  },
  onLoad(options) {
    var _this=this;
    var _cha= app.screenHeight - 1460;
    if(typeof(options.isf) != 'undefined'){
      _this.setData({isfrom:options.isf})
      if(2 == options.isf){
        _this.setData({z10: "hide"});
      }
   }
   console.log(options)

    if(_cha > 0){
      _this.setData({isTop:_cha/2});
      //_this.setData({isTop2: 264 + _cha/4});
    }


    wx.getStorage({
      key: 'openid',
      success (res) {
        app.globalData.openid=res.data;
        _this.checkisreg(res.data);
      },
      fail(res){
        _this.getLogin();
      }})
  },
  getLogin: function () {
    var _this=this;
    wx.login({
      success (res) {
        if (res.code) {
          app.globalData.loginCode=res.code;
          wx.request({
            url: 'https://mei94.com/chongya/web/?c=login',
            data: {cd: res.code},
            header: {'content-type': 'application/json' },
            success (res) {
               app.globalData.openid=res.data.o;
               wx.setStorage({ key:"openid",data: res.data.o });
              _this.checkisreg(res.data.o)
            }
          });
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }})
      
  },
  checkisreg(_openid){
    var _this=this;
    wx.request({
      url: app.domainName + 'web/?c=isreg',
      method: 'POST',
      data: {openid:_openid}, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
         if(2 == res.data.s){
           wx.redirectTo({url: '/pages/zdui/index'});
           return;
         }
         setTimeout(function(){
          _this.setData({fadeOut: "fadeOut animated"});
         }, 2000);
         setTimeout(function(){
          _this.setData({z10: "hide"});
         }, 3000);

         

         if(res.data.mt != ''){
          wx.showModal({
            showCancel:false,
            title: res.data.mbt,
            content: res.data.mt,
            success (res) {
            }
          })  
        }
         _this.setData({iswhow:''});
      }});
  },
  goLogin(){
    wx.request({
      url: app.domainName + 'web/?c=checkuser',
      method: 'POST',
      data: {openid:app.globalData.openid}, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
         if('y' == res.data.s){
          wx.redirectTo({url: '/pages/welcome/index'})
         }else{
           wx.redirectTo({url: '/pages/index/reg'})
         }
      }});
    
  },
  goxa(){
    wx.redirectTo({url: '/pages/xiangqing/index?xid=1&isf=2'})
  },
  goxb(){
    wx.redirectTo({url: '/pages/xiangqing/index?xid=2&isf=2'})
  },
  goxc(){
    wx.redirectTo({url: '/pages/xiangqing/index?xid=3&isf=2'})
  },
  goxd(){
    wx.redirectTo({url: '/pages/xiangqing/index?xid=4&isf=2'})
  },
  goxe(){
    wx.redirectTo({url: '/pages/xiangqing/index?xid=5&isf=2'})
  },
  lianxi(){
    wx.makePhoneCall({
      phoneNumber: '13681737112'
    })
  },
  popMsg(msg){
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 1500
    })
  }
})
